/**
 * <copyright>
 * </copyright>
 *

 */
package org.eclipse.gittab.gitTabDsl.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;
import org.eclipse.gittab.gitTabDsl.ChordLibrary;
import org.eclipse.gittab.gitTabDsl.GitTabDslPackage;
import org.eclipse.gittab.gitTabDsl.Import;
import org.eclipse.gittab.gitTabDsl.Tab;
import org.eclipse.gittab.gitTabDsl.TabModel;
import org.eclipse.gittab.gitTabDsl.Tuning;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Tab Model</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.eclipse.gittab.gitTabDsl.impl.TabModelImpl#getImports <em>Imports</em>}</li>
 *   <li>{@link org.eclipse.gittab.gitTabDsl.impl.TabModelImpl#getTuning <em>Tuning</em>}</li>
 *   <li>{@link org.eclipse.gittab.gitTabDsl.impl.TabModelImpl#getChordLibrary <em>Chord Library</em>}</li>
 *   <li>{@link org.eclipse.gittab.gitTabDsl.impl.TabModelImpl#getTab <em>Tab</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class TabModelImpl extends MinimalEObjectImpl.Container implements TabModel
{
  /**
   * The cached value of the '{@link #getImports() <em>Imports</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getImports()
   * @generated
   * @ordered
   */
  protected EList<Import> imports;

  /**
   * The cached value of the '{@link #getTuning() <em>Tuning</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getTuning()
   * @generated
   * @ordered
   */
  protected Tuning tuning;

  /**
   * The cached value of the '{@link #getChordLibrary() <em>Chord Library</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getChordLibrary()
   * @generated
   * @ordered
   */
  protected EList<ChordLibrary> chordLibrary;

  /**
   * The cached value of the '{@link #getTab() <em>Tab</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getTab()
   * @generated
   * @ordered
   */
  protected Tab tab;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected TabModelImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return GitTabDslPackage.Literals.TAB_MODEL;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<Import> getImports()
  {
    if (imports == null)
    {
      imports = new EObjectContainmentEList<Import>(Import.class, this, GitTabDslPackage.TAB_MODEL__IMPORTS);
    }
    return imports;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Tuning getTuning()
  {
    return tuning;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetTuning(Tuning newTuning, NotificationChain msgs)
  {
    Tuning oldTuning = tuning;
    tuning = newTuning;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, GitTabDslPackage.TAB_MODEL__TUNING, oldTuning, newTuning);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setTuning(Tuning newTuning)
  {
    if (newTuning != tuning)
    {
      NotificationChain msgs = null;
      if (tuning != null)
        msgs = ((InternalEObject)tuning).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - GitTabDslPackage.TAB_MODEL__TUNING, null, msgs);
      if (newTuning != null)
        msgs = ((InternalEObject)newTuning).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - GitTabDslPackage.TAB_MODEL__TUNING, null, msgs);
      msgs = basicSetTuning(newTuning, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, GitTabDslPackage.TAB_MODEL__TUNING, newTuning, newTuning));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<ChordLibrary> getChordLibrary()
  {
    if (chordLibrary == null)
    {
      chordLibrary = new EObjectContainmentEList<ChordLibrary>(ChordLibrary.class, this, GitTabDslPackage.TAB_MODEL__CHORD_LIBRARY);
    }
    return chordLibrary;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Tab getTab()
  {
    return tab;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetTab(Tab newTab, NotificationChain msgs)
  {
    Tab oldTab = tab;
    tab = newTab;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, GitTabDslPackage.TAB_MODEL__TAB, oldTab, newTab);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setTab(Tab newTab)
  {
    if (newTab != tab)
    {
      NotificationChain msgs = null;
      if (tab != null)
        msgs = ((InternalEObject)tab).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - GitTabDslPackage.TAB_MODEL__TAB, null, msgs);
      if (newTab != null)
        msgs = ((InternalEObject)newTab).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - GitTabDslPackage.TAB_MODEL__TAB, null, msgs);
      msgs = basicSetTab(newTab, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, GitTabDslPackage.TAB_MODEL__TAB, newTab, newTab));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case GitTabDslPackage.TAB_MODEL__IMPORTS:
        return ((InternalEList<?>)getImports()).basicRemove(otherEnd, msgs);
      case GitTabDslPackage.TAB_MODEL__TUNING:
        return basicSetTuning(null, msgs);
      case GitTabDslPackage.TAB_MODEL__CHORD_LIBRARY:
        return ((InternalEList<?>)getChordLibrary()).basicRemove(otherEnd, msgs);
      case GitTabDslPackage.TAB_MODEL__TAB:
        return basicSetTab(null, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case GitTabDslPackage.TAB_MODEL__IMPORTS:
        return getImports();
      case GitTabDslPackage.TAB_MODEL__TUNING:
        return getTuning();
      case GitTabDslPackage.TAB_MODEL__CHORD_LIBRARY:
        return getChordLibrary();
      case GitTabDslPackage.TAB_MODEL__TAB:
        return getTab();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case GitTabDslPackage.TAB_MODEL__IMPORTS:
        getImports().clear();
        getImports().addAll((Collection<? extends Import>)newValue);
        return;
      case GitTabDslPackage.TAB_MODEL__TUNING:
        setTuning((Tuning)newValue);
        return;
      case GitTabDslPackage.TAB_MODEL__CHORD_LIBRARY:
        getChordLibrary().clear();
        getChordLibrary().addAll((Collection<? extends ChordLibrary>)newValue);
        return;
      case GitTabDslPackage.TAB_MODEL__TAB:
        setTab((Tab)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case GitTabDslPackage.TAB_MODEL__IMPORTS:
        getImports().clear();
        return;
      case GitTabDslPackage.TAB_MODEL__TUNING:
        setTuning((Tuning)null);
        return;
      case GitTabDslPackage.TAB_MODEL__CHORD_LIBRARY:
        getChordLibrary().clear();
        return;
      case GitTabDslPackage.TAB_MODEL__TAB:
        setTab((Tab)null);
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case GitTabDslPackage.TAB_MODEL__IMPORTS:
        return imports != null && !imports.isEmpty();
      case GitTabDslPackage.TAB_MODEL__TUNING:
        return tuning != null;
      case GitTabDslPackage.TAB_MODEL__CHORD_LIBRARY:
        return chordLibrary != null && !chordLibrary.isEmpty();
      case GitTabDslPackage.TAB_MODEL__TAB:
        return tab != null;
    }
    return super.eIsSet(featureID);
  }

} //TabModelImpl
